home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / AppendDITL Demo / testShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-03  |  3.7 KB  |  152 lines  |  [TEXT/MMCC]

  1. /*
  2.     This shell was created to demonstrate the correct way to use AppendDITL(), CountDITL(),
  3.     and ShortenDITL() Dialog Manager calls in System7.  This shell also show how to corectly
  4.     use the WindowFont for drawing text in a dialog This demo creates a sample dialog which 
  5.     contains a checkbox control using the WindowFont.  This checkbox appends and shortens the
  6.     dialogs DITL.  
  7.     
  8.     This sample is provided with the following files:
  9.     testShell.µ        // CodeWarroir 1.1.1.2 project file
  10.     testShell.c        // source for this demo
  11.     testShell.rsrc    // resources for this demo
  12.     AppendDITLDem    // sample compiled app
  13.     
  14.     !!!NOTE: The correct way to do this is to use overlayDITL if you plan on
  15.     shrinking the dialog back and forth between the appended and normal length.  I far as
  16.     I can tell this is not fully documanted anywhere!!!
  17.     
  18.     This code was provided to me by Phil Kearney, III (otherwise known as just plain "Dude")
  19.     
  20.     Thanks Dude :)
  21.     
  22.     - Marty Wachter
  23.     mrw@welchgate.welch.jhu.edu or afaMarty@aol.com
  24.     
  25.  
  26. */
  27.  
  28.  
  29. void             main(void);
  30. static void        ToolboxInit(void);
  31. void             DoTestDialog(void);
  32.  
  33. // • main
  34. //
  35. void main(void)
  36. {
  37.     ToolboxInit();
  38.     DoTestDialog();
  39.     ExitToShell();
  40. }
  41.  
  42.  
  43. // • DoTestDialog
  44. //
  45. void DoTestDialog(void)
  46. {
  47.     DialogPtr    theDialog = nil;
  48.     short        item, wide, high, origCnt;
  49.     Handle        ditlHndl = nil;
  50.     FontInfo    fInfo;
  51.     
  52.     // get the dialog from the resource fork
  53.     theDialog = GetNewDialog(1025, nil, (WindowPtr)-1L);
  54.     if(!theDialog)
  55.         return;
  56.     
  57.     // save the original item count for later shortening of the DITL
  58.     origCnt = CountDITL(theDialog);
  59.     
  60.     // get a handle to the DITL to append
  61.     ditlHndl = Get1Resource('DITL', 1026);
  62.     if(!ditlHndl)
  63.         return;
  64.     
  65.     // lock it down until we are through with the dialog
  66.     HLock(ditlHndl);
  67.     
  68.     SetPort(theDialog);
  69.     
  70.     // the proper way to set the dialog's text to be drawn
  71.     // in some other font chicago.
  72.     TextFont(geneva);
  73.     TextSize(9);
  74.     GetFontInfo(&fInfo);
  75.     
  76.     (**(((DialogPeek)theDialog)->textH)).txFont = geneva;
  77.     (**(((DialogPeek)theDialog)->textH)).txSize = 9;
  78.     
  79.     (**(((DialogPeek)theDialog)->textH)).lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  80.     (**(((DialogPeek)theDialog)->textH)).fontAscent = fInfo.ascent;
  81.     
  82.     // save the original width and height for later shortening
  83.     wide = theDialog->portRect.right - theDialog->portRect.left;
  84.     high = theDialog->portRect.bottom - theDialog->portRect.top;
  85.     
  86.     // show our dialog
  87.     ShowWindow(theDialog);
  88.     
  89.     do {
  90.     
  91.         ModalDialog(nil, &item);
  92.         
  93.         if(item == 3) {        // our checkbox
  94.         
  95.             short    iType, numAppended;
  96.             Rect    iRect;
  97.             Handle    iHandle;
  98.             Boolean    checked;
  99.             
  100.             // see if the checkbox is checked or not
  101.             GetDItem(theDialog, item, &iType, &iHandle, &iRect);
  102.             checked = GetCtlValue((ControlHandle)iHandle);
  103.             
  104.             if(!checked) {
  105.                 // append the DITL using overlayDITL mode
  106.                 AppendDITL(theDialog, ditlHndl, overlayDITL);
  107.                 
  108.             } else {
  109.                 // shorten the DITL to it's original size
  110.                 
  111.                 // get the differnece of items in the dialog - the original count
  112.                 numAppended = CountDITL(theDialog) - origCnt;
  113.                 
  114.                 // shorten the DITL
  115.                 ShortenDITL(theDialog, numAppended);
  116.                 
  117.                 // resize the dialog to it's original dimensions
  118.                 SizeWindow(theDialog, wide, high, true);
  119.             }
  120.             
  121.             // reset the control's value
  122.             SetCtlValue((ControlHandle)iHandle, !checked);
  123.         }
  124.         
  125.     } while(item > ok);
  126.     
  127.     // unlock and release
  128.     HUnlock(ditlHndl);
  129.     ReleaseResource(ditlHndl);
  130.     
  131.     // get rid of our dialog
  132.     DisposeDialog(theDialog);
  133. }
  134.  
  135.  
  136. // • ToolboxInit
  137. // Standard set of calls to enable all the toolbox calls
  138. //
  139. static void ToolboxInit(void)
  140. {
  141.     InitGraf((Ptr)&qd.thePort);
  142.     InitFonts();
  143.     InitWindows();
  144.     InitMenus();
  145.     TEInit();
  146.     InitDialogs(0L);
  147.     InitCursor();
  148.     MaxApplZone();
  149.     MoreMasters();
  150.     MoreMasters();
  151.     MoreMasters();
  152.  }